package com.ycy.leetcode.dongtaiguihua;

/**
 * 最大子序和
 */
public class ZiXuHe {

  public static void main(String[] args) {
    int[] nums = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
    nums = new int[]{-2, -3};
    int i = maxSubArray(nums);
    System.out.println(i);
  }

  public static int maxSubArray(int[] nums) {
    int pre = 0, maxAns = nums[0];
    for (int x : nums) {

      pre = Math.max(pre + x, x);
      // 移动的过程中发现最大的
      maxAns = Math.max(maxAns, pre);
      System.out.println(x + " " + maxAns + " " + pre);
    }
    return maxAns;
  }


}
